import express from "express";
import {rateLimit} from "express-rate-limit"

// 限制请求频率
const limiter = rateLimit({
	windowMs: 1 * 30 * 1000, // 30秒内最多5次请求
	limit: 5, // 每30秒最多5次请求
	standardHeaders: true, // Return rate limit info in the `RateLimit-*` headers
	legacyHeaders: false, // Disable the `X-RateLimit-*` headers
})

const app = express();

app.use('*',(req, res, next) => {
    res.header('Access-Control-Allow-Origin', '*')
    next();
})

app.get("/hello", limiter, (req, res) => {
    res.send("Hello World")
})

// 启动服务
app.listen(3000, () => {
  console.log("服务启动成功 http://localhost:3000");
})
